﻿using System;
using System.Collections.Generic;
using System.Web;

namespace ForestryEnterprise
{
    public class Invoice
    {
        private List<Subinvoice> subInvoices;
        private float totalCost;
        private float totalDept;
        private int amountM3;
        private int amountPRM;

        public Invoice()
        {
            this.amountPRM = this.amountM3 = 0;
            this.subInvoices = new List<Subinvoice>();
        }

        public void addSubinvoice(Subinvoice sub)
        {
            this.subInvoices.Add(sub);

            if (sub.BuyType == 1)
            {
                this.amountM3 += sub.Amount;
            }
            else
            {
                this.amountPRM += sub.Amount;
            }

            this.totalCost += sub.Cost * sub.Amount;
        }

        public Subinvoice getSubinvoice(int treeID)
        {
            foreach (Subinvoice sub in this.subInvoices)
            {
                if (sub.TreeID == treeID)
                {
                    return sub;
                }
            }

            return null;
        }

        public List<Subinvoice> getSubinvoices()
        {
            return this.subInvoices;
        }

        public float TotalCost
        {
            set
            {
                this.totalCost = value;
            }
            get
            {
                return this.totalCost;
            }
        }

        public float TotalDept
        {
            set
            {
                this.totalDept = value;
            }
            get
            {
                return this.totalDept;
            }
        }

        public int AmountM3
        {
            set
            {
                this.amountM3 = value;
            }
            get
            {
                return this.amountM3;
            }
        }

        public int AmountPRM
        {
            set
            {
                this.amountPRM = value;
            }
            get
            {
                return this.amountPRM;
            }
        }
    }
}